import React, { Component } from 'react';
//导入tabBar
import TabBar from "../tabBar/tabBar"; 
//导入配置
import Global from "../../App.json"; 
//导入辅助函数
import {mapState, mapDispatch} from "../../store/mapFunction"; 

class common extends Component {
    componentDidMount(){
         //获取当前切换的页面路径
         if(this.props.meta.auther){
            //判断用户是否登录
            var random = 0;
            if(random === 0){
                this.props.history.replace("/kind");
            } 
        }
        //修改tabBar下标
        this.props.selectIndexAction(this.props.meta.selectIndex); 

    }
    componentDidUpdate(){
        //获取当前切换的页面路径
        if(this.props.meta.auther){
            //判断用户是否登录
            var random = 0;
            if(random === 0){
                this.props.history.replace("/kind");
            } 
        }
        //此时页面层级不为一级页面
        if(this.props.meta.deep > 1){
            //隐藏tabBar
            this.props.tabShowAction(false);
        } 
        //修改tabBar下标
        this.props.selectIndexAction(this.props.meta.selectIndex); 
    }
    render() {
        return (
            <div className="common">
                {this.props.children}
                {this.props.tabShow ? <TabBar lists={Global.tabBar.lists} {...this.props}/>:null}
            </div>
        );
    }
}

export default mapDispatch(mapState(common, ['tabShow']), ['tabShowAction', "selectIndexAction"]);